<template>
    <div class="goods-list">
        <!-- <router-link :to="'/home/goodsinfo/'+item.id" class="goods-item" v-for="item in goodslist" :key="item.id">
            <img :src="item.img_url" alt="">
            <h1 class="title">{{item.title}}</h1>
            <div class="info">
                <p class="price">
                    <span class="now">￥{{item.sell_price}}</span>
                    <span class="old">￥{{item.market_price}}</span>
                </p>
                <p class="sell">
                    <span>热卖中</span>
                    <span>剩{{item.stock_quantity}}件</span>
                </p>
            </div>
        </router-link> -->


        <!-- 使用window.location.href 的形式  编程式导航 -->
        <div class="goods-item" v-for="item in goodslist" :key="item.id" @click="goDetail(item.id)">
            <img :src="item.img_url" alt="">
            <h1 class="title">{{item.title}}</h1>
            <div class="info">
                <p class="price">
                    <span class="now">￥{{item.sell_price}}</span>
                    <span class="old">￥{{item.market_price}}</span>
                </p>
                <p class="sell">
                    <span>热卖中</span>
                    <span>剩{{item.stock_quantity}}件</span>
                </p>
            </div>
        </div>
        <!-- <div class="goods-item">
            <img src="../photo/pictrure/bz.jpg" alt="">
            <h1 class="title">华为（HuaWei）P30 Pro</h1>
            <div class="info">
                <p class="price">
                    <span class="now">￥5999</span>
                    <span class="old">￥5499</span>
                </p>
                <p class="sell">
                    <span>热卖中</span>
                    <span>剩余3件</span>
                </p>
            </div>
        </div> -->
        
    </div>
    
</template>

<script>
export default {
    data(){
        return {
            goodslist:[]
        }
    },
    created(){
        this.getGoodsList()
    },
    methods:{
        getGoodsList(){
            this.$http.get('goods/goodslist.json').then(result =>{
                if(result.body.status === 0){
                    this.goodslist = result.body.message
                }
            })
        },
        goDetail(id){
            this.$router.push("/home/goodsinfo/"+id)
        }
    }
}
</script>
<style lang="scss" scoped>
.goods-list{
    display: flex;
    flex-wrap: wrap;
    padding: 8px;
    justify-content: space-between;
    .goods-item{
        width: 49%;
        border: 1px solid #ccc;
        box-shadow: 0 0 8px #ccc;
        margin: 4px 0;
        display: flex;
        flex-direction: column;
        justify-content: space-between;
        min-height: 293px;
        img{
            width: 100%;
        }
        .title{
            font-size: 14px;
            color: rgb(0, 0, 0);
        }
        .info{
            background-color: #eee;
            p{
                padding: 5px;
                margin: 0;
            }
            .price{
                .now{
                    color: red;
                    font-weight: bold;
                    font-size: 12px;
                    margin-left: 10px;
                }
                .old{
                    text-decoration: line-through;
                    font-size: 10px;
                }
            }
            .sell{
                font-size: 12px;
                display: flex;
                justify-content: space-between;
            }
        }
    }
}
</style>
